// Dom7
var $$ = Dom7;

// Framework7 App main instance
var app = new Framework7({
	root: '#app', // App root element
	id: 'io.yachtar.app', // App bundle ID
  	name: 'Yachtar', // App name
	theme: 'auto', // Automatic theme detection
	dialog: {
		// set default title for all dialog shortcuts
		title: '提示',
		// change default "OK" button text
		buttonOk: '确认',
	  }
});

// Init/Create main view
var mainView = app.views.create('.view', {
	url: '/'
});
var housedatas;

$(document).ready(function() {
	$("#ul-list").empty();
	var serialno = sessionStorage.getItem("serialno");
	var givetype = sessionStorage.getItem("givetype");
	document.getElementById('all').style.background="#44b7fb";
	document.getElementById('all').style.color ="white";
	document.getElementById('yt').style.background="#f7f7f7";
	document.getElementById('yt').style.color ="black";
	document.getElementById('wt').style.background="#f7f7f7";
	document.getElementById('wt').style.color ="black";
	call_remote(REQUEST_TYPE830,{serialno:serialno,givetype:givetype},function(data){
		housedatas = data;
		for (var i = 0; i < housedatas.length; i++) {
			var elem_li = document.createElement('li');
			elem_li.setAttribute("class", "li-list");
			var elem_div = document.createElement("div");
			elem_div.setAttribute("class", "imgdiv");
			if(housedatas[i].ticketflag == "O"){
				elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
					+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
					+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>未投票</div>"
					+"</div>";
			}else{
				elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
					+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
					+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>已投票</div>"
					+"</div>";
			}
			document.getElementById('ul-list').appendChild(elem_li); 
			elem_li.appendChild(elem_div);
		}
	});
});

//返回
$$('#backimg').on('click', function () {
	window.location.href = "../../plugin/vote/votedetail.html";
});
//全部
$$('#all').on('click', function () {
	document.getElementById('all').style.background="#44b7fb";
	document.getElementById('all').style.color ="white";
	document.getElementById('yt').style.background="#f7f7f7";
	document.getElementById('yt').style.color ="black";
	document.getElementById('wt').style.background="#f7f7f7";
	document.getElementById('wt').style.color ="black";
	$("#ul-list").empty();
	for (var i = 0; i < housedatas.length; i++) {
		var elem_li = document.createElement('li');
		elem_li.setAttribute("class", "li-list");
		var elem_div = document.createElement("div");
		elem_div.setAttribute("class", "imgdiv");
		if(housedatas[i].ticketflag == "O"){
			elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
				+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
				+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>未投票</div>"
				+"</div>";
		}else{
			elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
				+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
				+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>已投票</div>"
				+"</div>";
		}
		document.getElementById('ul-list').appendChild(elem_li); 
		elem_li.appendChild(elem_div);
	}
});
//未投票
$$('#wt').on('click', function () {
	$("#ul-list").empty();
	document.getElementById('all').style.background="#f7f7f7";
	document.getElementById('all').style.color ="black";
	document.getElementById('yt').style.background="#f7f7f7";
	document.getElementById('yt').style.color ="black";
	document.getElementById('wt').style.background="#44b7fb";
	document.getElementById('wt').style.color ="white";
	for (var i = 0; i < housedatas.length; i++) {
		if(housedatas[i].ticketflag == "O"){
			var elem_li = document.createElement('li');
			elem_li.setAttribute("class", "li-list");
			var elem_div = document.createElement("div");
			elem_div.setAttribute("class", "imgdiv");
			elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
				+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
				+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>未投票</div>"
				+"</div>";
			document.getElementById('ul-list').appendChild(elem_li); 
			elem_li.appendChild(elem_div);
		}
	}
});
//已投票
$$('#yt').on('click', function () {
	$("#ul-list").empty();
	document.getElementById('all').style.background="#f7f7f7";
	document.getElementById('all').style.color ="black";
	document.getElementById('yt').style.background="#44b7fb";
	document.getElementById('yt').style.color ="white";
	document.getElementById('wt').style.background="#f7f7f7";
	document.getElementById('wt').style.color ="black";
	for (var i = 0; i < housedatas.length; i++) {
		if(housedatas[i].ticketflag != "O"){
			var elem_li = document.createElement('li');
			elem_li.setAttribute("class", "li-list");
			var elem_div = document.createElement("div");
			elem_div.setAttribute("class", "imgdiv");
			elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:40px;'>"
				+"<div class='col-80' style='text-align: left; font-size:20px;height:40px;line-height:40px;'>"+housedatas[i].location+"</div>"
				+"<div class='col-20' style='text-align: center; font-size:20px;height:40px;line-height:40px;'>已投票</div>"
				+"</div>";
			document.getElementById('ul-list').appendChild(elem_li); 
			elem_li.appendChild(elem_div);
		}
	}
});